package com.example.taximeter.controller;


import com.example.taximeter.bean.ReturnInfo;
import com.example.taximeter.bean.Search;
import com.example.taximeter.bean.TaximeterView;
import com.example.taximeter.service.SearchService;
import com.example.taximeter.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 查询管理
 */
@RestController
@RequestMapping(value = "/search", method = RequestMethod.POST)
public class SearchController {

    private SearchService searchService;
    private UserService userService;

    @Autowired
    public SearchController(SearchService searchService,UserService userService){
        this.searchService = searchService;
        this.userService = userService;
    }

    //查看计价器列表
    @RequestMapping(value = "/all")
    public ReturnInfo findSearchAll(@RequestParam(value = "pageNum", defaultValue = "0") String pageNum,
                                       @RequestParam(value = "pageSize", defaultValue = "0") String pageSize,
                                       @RequestBody Search search) {
        //添加日志
        userService.addUserLog(7,search.toString());
        return searchService.findSearchAll(Integer.valueOf(pageNum), Integer.valueOf(pageSize), search);
    }

    //查看最新版本数量
    @RequestMapping(value = "/newnum")
    public Integer findNewNum(@RequestParam String companyname) {
        //添加日志
        userService.addUserLog(8,companyname+"最新版本数量");
        return searchService.findNewNum(companyname);
    }

    //查看非最新版本数量
    @RequestMapping(value = "/notnewnum")
    public Integer findNotNewNum(@RequestParam String companyname) {
        //添加日志
        userService.addUserLog(8,companyname+"非最新版本数量");
        return searchService.findNotNewNum(companyname);
    }
}
